package com.bjwl.service.impl;

import com.bjwl.dao.BsadminMapper;
import com.bjwl.pojo.Bsadmin;
import com.bjwl.pojo.Business;
import com.bjwl.pojo.vo.BsAdminQueryVo;
import com.bjwl.service.BsadminService;
import com.bjwl.utils.PageBean;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.test.annotation.Commit;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Author: dzx
 * @Date:Create：in 2020/4/10 15:55
 * @Description:    分店管理员逻辑层
 * @Modified By：
 * @Version: 1.0
 */
@Service
public class BsadminServiceImpl implements BsadminService {

    @Autowired
    private BsadminMapper bsadminMapper;

    @Override
    @Transactional
    public void addBsadmin(Bsadmin bsadmin) {
        bsadminMapper.addBsadmin(bsadmin);
    }

    @Override
    @Transactional
    public void deleteBsadminById(Bsadmin bsadmin) {
        bsadminMapper.deleteBsadminById(bsadmin);
    }

    @Override
    @Transactional
    public void updateBsadminById(Bsadmin bsadmin) {
        bsadminMapper.updateBsadminById(bsadmin);
    }

    @Override
    public Bsadmin findBsadminById(Bsadmin bsadmin) {
        return bsadminMapper.findBsadminById(bsadmin);
    }

    @Override
    public List<Bsadmin> findBsadminsByBsid(Bsadmin bsadmin) {
        return bsadminMapper.findBsadminsByBsid(bsadmin);
    }

    @Override
    public Bsadmin findBsadminByUserNameAndPassWord(Bsadmin bsadmin) {
        return bsadminMapper.findBsadminByUserNameAndPassWord(bsadmin);
    }

    @Override
    public PageBean<Bsadmin> findBsAdminsByBranchStore(Integer pageNum, Integer bsId, String username) {
        PageBean<Bsadmin> pageBean = new PageBean<Bsadmin>(pageNum,10,bsadminMapper.getTotalRecord(bsId,username));
        BsAdminQueryVo bsAdminQueryVo = new BsAdminQueryVo();
        bsAdminQueryVo.setBsId(bsId);
        bsAdminQueryVo.setPageBean(pageBean);
        bsAdminQueryVo.setUsername(username);
        pageBean.setData(bsadminMapper.findBsAdminsByBranchStore(bsAdminQueryVo));
        return pageBean;
    }

    @Override
    public void addBsAdmin(Bsadmin bsadmin) {
        bsadminMapper.addBsadmin(bsadmin);
    }

    @Override
    public List<Bsadmin> findBsMinByBsid(Integer bsid) {
        return bsadminMapper.findBsMinByBsid(bsid);
    }

    //修改管理员信息(展示要修改的数据)
    @Override
    public Bsadmin updateShowBsadmin(Integer id) {
       return bsadminMapper.updateShowBsadmin(id);
    }

    @Override
    public Integer bsadminCound(Integer bsid) {
        return bsadminMapper.bsadminCound(bsid);
    }

    //*****************************************************


    @Override
    public PageBean<Bsadmin> findBusinessMin(Integer pageNum, Integer bsid, String username) {
        PageBean<Bsadmin> bsadminPageBean = new PageBean<Bsadmin>(pageNum,8,bsadminMapper.getTotalRecordBsMin(bsid,username));
        bsadminPageBean.setData(bsadminMapper.findBusinessMin(bsadminPageBean,bsid,username));
        return bsadminPageBean;
    }

    @Override
    public List<Bsadmin> findBsadminByName(String username) {
        return bsadminMapper.findBsadminByName(username);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public void stateBsAdmin(Bsadmin bsadmin) {
        bsadminMapper.stateBsAdmin(bsadmin);
    }
}
